package com.restfinder.comment.model;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import lombok.Getter;
import lombok.Setter;

import com.restfinder.model.IEntity;
import com.restfinder.restaurant.model.Restaurant;
import com.restfinder.user.model.User;

@Entity
@Table(name="comments")
public class Comment implements IEntity {

	private static final long serialVersionUID = 1L;
	
	@Id
	@GeneratedValue
	@Getter @Setter
	private long id;
	@Getter @Setter
	private String content;
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="user_id")
	@Getter @Setter
	private User user;
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="restaurant_id")
	@Getter @Setter
	private Restaurant restaurant;
	@Getter @Setter
	private Date date;

	
	@Override
	public boolean equals(Object obj) {
		if(this == obj) return true;
		if ((obj == null) || !(obj instanceof Comment)) {
			return false;
		}
		Comment comment = (Comment) obj;
		return comment.getId() == this.id;		
	}

	@Override
	public String toString() {
		return "Comment.id="+this.id;
	}
}
